package itdep.domain.event;

import itdep.domain.IisEntity;
import itdep.domain.student.Student;
import itdep.domain.student.StudentGroup;
import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;

/**
 * @author kara (latest modification by kara)
 * @version $Revision: 11 $   $Date: 2010-06-16 10:18:57 +0000 (Wed, 16 Jun 2010) $
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula(value = "EVENT_TYPE")
@DiscriminatorValue(value = "0")
@Table(name = "STUDENT_EVENT")
public class StudentEvent extends IisEntity {

	@ManyToOne(targetEntity = Student.class, fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
	@JoinColumn(name = "ID_STUDENT", nullable = false, insertable = true, updatable = true)
	private Student student;

	//date of creating event, get current time
	@Column(name = "MODIFY_DATE", nullable = true, insertable = true, updatable = true)
	private Date modifyDate = new Date();

	@Column(name = "COMMENTARY", nullable = true, insertable = true, updatable = true)
	private String commentary;

	/**
	 * Use user type to define order of event type
	 */
	@Type(type = "itdep.hibernate.OrderedEnumUserType", parameters = {@Parameter(name = "enumClass", value = "itdep.model.dictionary.EventType")})
	@Column(name = "EVENT_TYPE", nullable = false, insertable = true, updatable = true)
	private EventType eventType;

	@ManyToOne(targetEntity = EventReason.class, fetch = FetchType.LAZY, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
	@JoinColumn(name = "ID_EVENT_REASON", nullable = false, insertable = true, updatable = true)
	private EventReason eventReason;

	@ManyToOne(targetEntity = Directive.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_DIRECTIVE", nullable = false, insertable = true, updatable = true)
	private Directive directive;

	@ManyToOne(targetEntity = StudentGroup.class, fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_OLD_STUDENT_GROUP", nullable = true, insertable = true, updatable = true)
	private StudentGroup oldStudentGroup;

	public Student getStudent() {
		return student;
	}

	public void setStudent(final Student student) {
		this.student = student;
	}

	public Date getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(final Date modifyDate) {
		this.modifyDate = modifyDate;
	}

	public String getCommentary() {
		return commentary;
	}

	public void setCommentary(final String commentary) {
		this.commentary = commentary;
	}

	public EventType getEventType() {
		return eventType;
	}

	public void setEventType(final EventType eventType) {
		this.eventType = eventType;
	}

	public Directive getDirective() {
		return directive;
	}

	public void setDirective(final Directive directive) {
		this.directive = directive;
	}

	public EventReason getEventReason() {
		return eventReason;
	}

	public void setEventReason(final EventReason eventReason) {
		this.eventReason = eventReason;
	}

	public StudentGroup getOldStudentGroup() {
		return oldStudentGroup;
	}

	public void setOldStudentGroup(final StudentGroup oldStudentGroup) {
		this.oldStudentGroup = oldStudentGroup;
	}
}